package alfred.mdp.messages.worker;

import alfred.mdp.Majordomo;
import alfred.mdp.messages.ProtocolMessage;
import org.zeromq.ZFrame;
import org.zeromq.ZMsg;

/**
 * Request <br>
 * Frame 0: Empty frame<br>
 * Frame 1: "MDPW01" (six bytes, representing MDP/Worker v0.1)<br>
 * Frame 2: 0x02 (one byte, representing REQUEST)<br>
 * Frame 3: Client address (envelope stack)<br>
 * Frame 4: Empty (zero bytes, envelope delimiter)v
 * Frames 5+: Request body (opaque binary)<br>
 */
public class Request extends ProtocolMessage {

    public Request(ZFrame clientAddress, ZMsg message) {
        super(
                Majordomo.EMPTY,
                Majordomo.PROTOCOL_WORKER_V,
                Majordomo.Worker.REQUEST,
                clientAddress,
                Majordomo.EMPTY
        );
        getZMsg().addAll(message);
    }

    public Request(ZMsg receivedMessage) {
        super(receivedMessage);
    }

    public ZMsg getBody() {
        return getSubMsg(5);
    }

    public ZFrame getClientAddress() {
        return get(3);
    }

}
